#pragma once
#ifdef __ANDROID__

#include "../../IGLProcLoader.h"
#include <android/surface_texture_jni.h>
#include <EGL/egl.h>
#include <android/log.h>

class AGLProcLoader : public IGLProcLoader {
public:
    AGLProcLoader() = default;
    
    void* getProcAddress(const char* name) const override { return reinterpret_cast<void*>(eglGetProcAddress(name)); }
};

class ARenderer {
public:
    static void createEGLContext(ASurfaceTexture* surfaceTexture);

private:
    ARenderer() = default;

    static void startRendering();
    static void destroyEGL();

    static void printDebugInfo(int modelRecvNO = -1);

    static void swapBuffer() {
        if (s_eglDisplay == EGL_NO_DISPLAY)
            return;
        EGLBoolean success = eglSwapBuffers(s_eglDisplay, s_eglSurface);
        if (!success)
            __android_log_print(ANDROID_LOG_ERROR, "ARenderer", "%s", "eglSwapBuffers fail!");
    }

    static ASurfaceTexture* s_surfaceTexture;
    static EGLDisplay s_eglDisplay;
    static EGLSurface s_eglSurface;
    static EGLContext s_eglContext;
};

#endif